package com.lhm.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;

@Configuration
@EnableResourceServer
public class MyResourceServerConfig extends ResourceServerConfigurerAdapter {
    @Override
    public void configure(HttpSecurity http) throws Exception {
        // 对 api/user 请求进行拦截
        http.requestMatchers().antMatchers("/api/**")
                .and()
                .authorizeRequests()           // 访问这个网址需要 G的身份
                .antMatchers("/api/adm/**").hasAnyAuthority("G")
                                            // 访问这个网址需要 P的身份
                .antMatchers("/api/fore/**").hasAnyAuthority("P")
                                             // 访问这个网址无需身份 公开的
                .antMatchers("/api/public/**").permitAll()
                        //其他网址都需要认证菜呢个访问
                .anyRequest().authenticated();
    }
}
